//
//  SiXCSourceModelItem.m
//  scheme-indent-xcplugin
//
//  Created by Ende on 10/12/29.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import "SiXCSourceModelItem.h"


@implementation XCSourceModelItem (SiPlugin)

- (BOOL)isEqualToIdentifier:(NSString *)identifier {
	return [[XCLanguageSpecification _identifierForUniqueId: [self langId]] isEqualToString: identifier];
}

- (id)childAfterLocation:(NSUInteger)location {
	return [self childAfterLocation: location index: nil];
}

- (id)childAfterLocation:(NSUInteger)location index:(NSUInteger *)index {
	NSUInteger temp = 0;
	
	for (XCSourceModelItem *item in [self children]) {
		if (location <= [item range].location) {
			if (index) *index = temp;
			return item;
		}
		temp++;
	}
	if (index) *index = NSNotFound;
	return nil;
}

- (id)childBeforeLocation:(NSUInteger)location {
	return [self childBeforeLocation: location index: nil];
}

- (id)childBeforeLocation:(NSUInteger)location index:(NSUInteger *)index {
	NSUInteger temp = [self numberOfChildren]-1;
	
	for (XCSourceModelItem *item in [[self children] reverseObjectEnumerator]) {
		if ([item range].location < location) {
			if (index) *index = temp;
			return item;
		}
		temp--;
	}
	if (index) *index = NSNotFound;
	return nil;
}

@end
